package com.liull.netty.itcast.nio.bytebuffer;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

/**
 * @Author: liull
 * @Description:
 * @Date: Created in 23:27 2021/7/21
 * @Modified By:
 */
public class GatheringWritesTest {
    public static void main(String[] args) {
        ByteBuffer buffer1 = StandardCharsets.UTF_8.encode("one");
        ByteBuffer buffer2 = StandardCharsets.UTF_8.encode("two");
        ByteBuffer buffer3 = StandardCharsets.UTF_8.encode("three");
        try (RandomAccessFile raf = new RandomAccessFile("gathering.txt", "rw")) {
            FileChannel channel = raf.getChannel();
            channel.write(new ByteBuffer[] {
                    buffer1, buffer2, buffer3
            });
        } catch (IOException e) {

        }
    }
}
